package com.zhou.controller;

import com.zhou.service.DriverService;
import com.zhou.utis.result.Result;
import com.zhou.vo.driver.InsertDriverVO;
import com.zhou.vo.driver.UpdateDriverVO;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @author zhouyuyan
 */
@RestController
@RequestMapping("driver")
public class DriverController {
    @Resource
    private DriverService driverService;
    @PostMapping("add")
    private Result add(@RequestBody InsertDriverVO vo){
        try {
            return Result.success(driverService.add(vo));
        }catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }

    /**
     * 修改司机信息
     * @return true or false
     */
    @PutMapping("update")
    private Result update(@RequestBody UpdateDriverVO vo){
        try {
            return Result.success(driverService.update(vo));
        }catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }
    /**
     * 根据id查询司机信息
     */
    @GetMapping("getById/{id}")
    private Result getById(@PathVariable("id") String id){
        try {
            return Result.success(driverService.getById(id));
        }catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }
    /**
     * 分页查询
     */
    @GetMapping("getAll")
    private Result getAll(@RequestParam(defaultValue = "1") Integer page,@RequestParam(defaultValue = "10")Integer pageSize){
        try {
            return Result.success(driverService.getAll(page,pageSize));
        }catch (RuntimeException e){
            return Result.error(e.getMessage());
        }
    }
}
